import { ObjectDirective } from 'vue'  //ObjectDirective: TS定义的一个接口
import { hasPermission } from '@/utils/permission/hasPermission'

export const permission:ObjectDirective = {
    mounted(el:HTMLButtonElement,binding,vnode){

        if(binding.value == undefined) return;

        const {action, effect} = binding.value;
        // 如果action不传，则认为不需要授权认证
        if(action == undefined){ return }

        if(!hasPermission(action)){
            if(effect == 'disabled'){
                el.disabled = true;
                el.setAttribute('title','无权限')
            }else{
                el.remove();
            }
            console.log(action,effect)
        }

    }
}